// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   commonPage_register_ok.java

package ecommerce.config.website;

import com.jspsmart.upload.*;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class commonPage_register_ok extends HttpServlet
{

	public commonPage_register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 ecommerce_db = new nseer_db_backup1(dbApplication);
			if (ecommerce_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				getAttachmentLength getAttachmentLength = new getAttachmentLength();
				getAttachmentType getAttachmentType = new getAttachmentType();
				addHref addHref = new addHref(dbApplication);
				double d = getAttachmentLength.getAttachmentLength((String)dbSession.getAttribute("unit_db_name"), "document_config_public_char");
				String ee = getAttachmentType.getAttachmentType((String)dbSession.getAttribute("unit_db_name"), "document_config_public_char");
				mySmartUpload.initialize(pageContext);
				mySmartUpload.upload();
				String file_name[] = new String[mySmartUpload.getFiles().getCount()];
				int j = 0;
				for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
				{
					SmartFile file = mySmartUpload.getFiles().getFile(i);
					if (file.isMissing())
					{
						j++;
					} else
					{
						File filea = new File((new StringBuilder(String.valueOf(path))).append("ecommerce/commonPage_template/").append(file.getFileName()).toString());
						if ((double)file.getSize() > d || filea.exists())
							j++;
					}
				}

				if (j != 0)
				{
					response.sendRedirect("ecommerce/config/website/commonPage_register_ok_a.jsp");
				} else
				{
					SmartFile file = mySmartUpload.getFiles().getFile(0);
					file_name[0] = file.getFileName();
					if (file.getFileName().indexOf(".jsp") != file.getFileName().length() - 4)
						j++;
					SmartFile file1 = mySmartUpload.getFiles().getFile(1);
					if (file1.getFileName().indexOf(".gif") != file1.getFileName().length() - 4 && file1.getFileName().indexOf(".jpg") != file1.getFileName().length() - 4 && file1.getFileName().indexOf(".bmp") != file1.getFileName().length() - 4 && file1.getFileName().indexOf(".png") != file1.getFileName().length() - 4)
						j++;
					String topic = mySmartUpload.getRequest().getParameter("topic");
					String register = mySmartUpload.getRequest().getParameter("register");
					String register_ID = mySmartUpload.getRequest().getParameter("register_ID");
					String register_time = mySmartUpload.getRequest().getParameter("register_time");
					if (j != 0)
					{
						response.sendRedirect("ecommerce/config/website/commonPage_register_ok_c.jsp");
					} else
					{
						file.saveAs((new StringBuilder(String.valueOf(path))).append("portal/").append(file.getFileName()).toString());
						file = mySmartUpload.getFiles().getFile(1);
						file_name[1] = file.getFileName();
						file.saveAs((new StringBuilder(String.valueOf(path))).append("ecommerce/commonPage_template/").append(file.getFileName()).toString());
						String sql = (new StringBuilder("insert into ecommerce_web_template_ii(topic,filename,attachment1,register,register_ID,register_time) values('")).append(topic).append("','").append(file_name[0]).append("','").append(file_name[1]).append("','").append(register).append("','").append(register_ID).append("','").append(register_time).append("')").toString();
						ecommerce_db.executeUpdate(sql);
						response.sendRedirect("ecommerce/config/website/commonPage_register_ok_b.jsp");
					}
				}
				ecommerce_db.commit();
				ecommerce_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
